package com.example.thymeleaftest.controller;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {
    @Value("${spring.thymeleaf.cache}")
    String cache;
    @RequestMapping("/test")
    @ResponseBody
    public String test1()  {
        System.out.println("--------" + cache);
        String s = "hello";
        return s;
    }
    @GetMapping("/index")
    public String add(ModelMap mmap) {
        ArrayList<String> books = new ArrayList<>();
        books.add("chinese");
        books.add("english");
//        thymeleaf不会将结果渲染成html
        User user = new User(12, "<h1>李白</h1>",books);
//        User user = new User(12, "李白",books);
        mmap.put("user",user);
        return "index";
    }
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    class User {
        Integer age;
        String name;
        List<String> books;
    }
}
